package com.szxy;

import com.szxy.service.BusinessService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zwz
 * @Date:2020/7/15 22:53
 * @Description:com.szxy
 * @Version:1.0
 **/
@SpringBootApplication
@EnableDiscoveryClient
@RestController
@EnableFeignClients   // 开启 Feign 调用
public class BusinessServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(BusinessServiceApplication.class, args);
    }

    @Autowired
    private BusinessService businessService;

    /**
     * 购买商品
     * @param userId 用户 ID
     * @param productId  商品号
     * @param count 商品数量
     * @return
     */
    @GlobalTransactional // 全局事务
    @GetMapping("/purchase/{userId}/{productId}/{count}")
    public ResponseEntity purchase(
            @PathVariable String userId,
            @PathVariable String productId,
            @PathVariable Integer count) {
        this.businessService.purcase(userId, productId, count);
        return ResponseEntity.ok("下单成功 ....");
    }

}
